<template>
    <!-- 页面容器 -->
    <div class="page-container">
        <!-- 卡片 -->
        <el-card class="box-card">
            <!-- 卡片头部 -->
            <div slot="header" class="clearfix">
                <span>我的入住订单</span>
            </div>
            <!-- 表单 -->
            <el-form :inline="true" class="demo-form-inline" :model="searchForm">
                <el-form-item label="备注">
                    <el-input placeholder="请输入备注" v-model="searchForm.remark" clearable></el-input>
                </el-form-item>
                <el-form-item label="状态">
                    <el-select v-model="searchForm.status" clearable>
                        <el-option label="已预订" :value="1"></el-option>
                        <el-option label="已入住" :value="2"></el-option>
                        <el-option label="已退房" :value="3"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleSearch">查询</el-button>
                </el-form-item>
            </el-form>

            <!-- 表格 -->
            <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row
                size="small">
                <el-table-column align="center" label="ID" prop="id"></el-table-column>
                <el-table-column align="center" label="用户" prop="member.name"></el-table-column>
                <el-table-column align="center" label="电话" prop="member.phone"></el-table-column>
                <el-table-column align="center" label="身份证" prop="member.idcard" show-overflow-tooltip></el-table-column>
                <el-table-column align="center" label="性别" prop="member.gender">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.member.gender == 1" type="success">男</el-tag>
                        <el-tag v-if="scope.row.member.gender == 2" type="danger">女</el-tag>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="房型" prop="room.category.categoryName"></el-table-column>
                <el-table-column align="center" label="房号" prop="room.roomNum"></el-table-column>
                <el-table-column align="center" label="入住时间" prop="startTime">
                    <template slot-scope="scope">
                        {{ scope.row.startTime.slice(0, 10) }}
                    </template>
                </el-table-column>
                <el-table-column align="center" label="居住天数" prop="days"></el-table-column>
                <el-table-column align="center" label="状态" prop="status">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.status == 1" type="warning">已预订</el-tag>
                        <el-tag v-if="scope.row.status == 2" type="success">已入住</el-tag>
                        <el-tag v-if="scope.row.status == 3" type="danger">已退房</el-tag>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="备注" prop="remark" show-overflow-tooltip></el-table-column>
                <el-table-column align="center" label="实付金额" prop="money">
                    <template slot-scope="scope">
                      {{ scope.row.money * scope.row.days }}
                    </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="100">
                    <template slot-scope="scope">
                        <el-popconfirm title="确定删除吗？" @confirm="deleteCofirm(scope.row)">
                            <el-button type="text" slot="reference" size="small">删除</el-button>
                        </el-popconfirm>
                    </template>
                </el-table-column>
            </el-table>

            <!-- 分页器 -->
            <el-pagination class="page-box" background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="pageNum" :page-sizes="[10, 20]" :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </el-card>
    </div>
</template>

<script>
import { findOrdersPageAPI, removeOrdersAPI } from "@/api/orders";
export default {
    name: 'MyOrder',

    data() {
        return {
            list: null,
            listLoading: true,
            pageSize: 10,
            pageNum: 1,
            total: 0,
            searchForm: {},
        };
    },

    mounted() {
        this.fetchData();
    },

    methods: {
        handleSizeChange(val) {//每页显示条数改变
            this.pageSize = val;
            this.fetchData();
        },
        handleCurrentChange(val) {//当前页码改变
            this.pageNum = val;
            this.fetchData();
        },
        handleSearch() {//点击搜索按钮
            this.fetchData();
        },
        async fetchData() {//查询数据
            this.listLoading = true;
            let response = await findOrdersPageAPI(
                this.pageNum,
                this.pageSize,
                this.searchForm
            );
            this.list = response.data.records;
            this.total = response.data.total;
            this.listLoading = false;
        },
        async deleteCofirm(row) {//点击确定删除按钮
            this.pageNum = 1;
            const res = await removeOrdersAPI(row.id);
            this.$message({
                message: res.message,
                type: res.flag ? "success" : "error",
            });
            this.fetchData();
        },
    },
};
</script>

<style lang="less" scoped>
@deep-bg: linear-gradient(135deg, #232946 0%, #393e46 100%);
@gold: #ffd700;
@main-blue: #409EFF;
@light-gray: #bbb;

.page-container {
    width: 1200px;
    margin: 20px auto;
}
.page-box {
  margin-top: 20px;
}
.el-table__cell, .el-table__header th {
    color: @light-gray !important;
}
.text-bold, .font-bold, .bold {
    color: #bbb !important;
    font-weight: bold;
}
.el-card, .el-dialog, .el-card__body {
    background: #232946 !important;
    border-radius: 12px !important;
    box-shadow: 0 4px 24px rgba(0,0,0,0.18) !important;
    border: 1.5px solid #ffd700 !important;
    color: #fff !important;
}
.el-dialog__header, .el-dialog__footer {
    background: #232946 !important;
    border: none !important;
}

// 表格美化，灰白色风格
/deep/ .el-table__cell {
  color: #232946 !important;
  background: #f5f6fa !important;
  border-bottom: 1px solid #e5e6ec !important;
}
/deep/ .el-table__header th {
  background: #e5e6ec !important;
  color: #232946 !important;
  border-bottom: 1.5px solid #d3d4db !important;
}
/deep/ .el-table__row {
  background: #f5f6fa !important;
}
/deep/ .el-table__row:hover {
  background: #ececf0 !important;
}
</style>